package com.hangzhou.xyj.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.model.GroupModel;
import com.hangzhou.xyj.ui.widget.views.MyTextView;

import java.util.List;

/**
 * Created by Administrator on 2016/1/14.
 */
public class NearbyGroupAdapter extends BaseAdapter {
    private List<GroupModel> mDatas;
    private Context mContext;
    private LayoutInflater mInflater;


    public NearbyGroupAdapter(Context context, List<GroupModel> datas) {
        this.mDatas = datas;
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.layout_nearby_group_item, parent, false);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        holder.mTvGroupName.setText(mDatas.get(position).getGroupName());
        return convertView;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        MyTextView mTvGroupName;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTvGroupName = (MyTextView) itemView.findViewById(R.id.tv_group_name);
        }
    }
}
